package com.gitee.wsl.doc.prosemirror.model.dom

import com.gitee.wsl.serialization.json.AnySerializer
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.MapSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.json.Json
import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.modules.contextual

@Suppress("UNCHECKED_CAST")
val JSON: Json by lazy {
    Json {
        ignoreUnknownKeys = true
        serializersModule = SerializersModule {
            contextual(AnySerializer)
            contextual(String.serializer())
            contextual(Int.serializer())
            contextual(Double.serializer())
            contextual(Long.serializer())
            contextual(Boolean.serializer())
            contextual(ListSerializer(AnySerializer) as KSerializer<ArrayList<*>>)
            contextual(MapSerializer(String.serializer(), AnySerializer) as KSerializer<LinkedHashMap<*, *>>)
        }
    }
}